package com.gec.controller;

import com.gec.dao.BookDao;
import com.gec.dao.BookDao1;
import com.gec.dao.BookDao2;
import com.gec.entity.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * 根据id来查询客房信息
 */
@WebServlet("/GetBookByIdServlet2")
public class GetBookByIdServlet2 extends HttpServlet {

    /**
     * 1、	获取修改的客房信息 根据id去获取要修改的客房 显示到一个新的页面去
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //获取客房编号

        //GetBookByIdServlet?id=${book.id }？可以在url地址中携带参数来请求服务器
        String id = request.getParameter("id");
        //调用根据客房编号查询客房的方法
        BookDao2 bookDao = new BookDao2();
        //调用根据编号查询客房的方法
        Book books = bookDao.getBookById(id);

        String name = books.name;
        String author = books.author;
        String price = books.price;
        String  sql = "insert into custom1 values (?,?,?,?)";
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(id);
        objects.add(name);
        objects.add(author);
        objects.add(price);
        bookDao.update(sql,objects);

        //将客房信息传递到修改客房信息页面

        request.getRequestDispatcher("x.jsp").forward(request,response);
    }
}
